//
//  xsDigitalRobotBottomView.m
//  digital_robot_demo
//
//  Created by xskj on 2024/8/29.
//

#import "xsDigitalRobotBottomView.h"
//#import "Masonry.h"
#import "xsDigitalRobotModel.h"

#define xrandomColor  [UIColor colorWithRed:(arc4random() %255)/255.0f green:(arc4random() %255)/255.0f blue:(arc4random() %255)/255.0f alpha:1.0f]
#define xsDigitalRobotScrollViewHeight 40.0

//颜色
#define COLOR_HEX(hexString)     [UIColor colorWithRed:((float)((hexString &0xFF0000) >>16))/255.0 green:((float)((hexString &0xFF00) >>8))/255.0 blue:((float)(hexString &0xFF))/255.0 alpha:1.0]

@interface xsDigitalRobotBottomView()<UIScrollViewDelegate,UITextViewDelegate>

// 是否设置过素材文本
@property (nonatomic,assign) BOOL isHadMaterialLabel;
// 是否设置过music文本
@property (nonatomic,assign) BOOL isHadMyVoiceButtonTitle;


@property (nonatomic, strong) UIView *xsContentView;
@property (nonatomic, strong) UIView *topView;

//切换数字人音色
@property (nonatomic, strong) UIButton *changeAudioButton;// 切换数字机器人声音
@property (nonatomic, strong) UIImageView *changeAudioImageV;
@property (nonatomic, strong) UILabel *changeAudioLabel;

//@property (nonatomic, strong) UIButton *xsMaterialButton;// 素材
@property (nonatomic, strong) UIImageView *xsMaterialImageV;
@property (nonatomic, strong) UILabel *xsMaterialLabel;

//@property (nonatomic, strong) UIButton *xsTitleButton;// 标题
@property (nonatomic, strong) UIImageView *xsTitleImageV;
@property (nonatomic, strong) UILabel *xsTitleLabel;

@property (nonatomic, strong) UIButton *xsSubtitlesButton;// 字幕
@property (nonatomic, strong) UIImageView *xsSubtitlesImageV;;
@property (nonatomic, strong) UILabel *xsSubtitlesLabel;

//@property (nonatomic, strong) UIScrollView *xsDigitalRobotScrollView;
@property (nonatomic, strong) UILabel *xsVideoTitleLabel;
//@property (nonatomic,strong)UIView *xsDigitalRobotSubBgView;
//@property (nonatomic,strong)NSMutableArray *DigitalRobotMarray;


@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UIButton *xsAddMaterialButton;// 添加素材
@property (nonatomic, strong) UIImageView *xsAddMaterialImageV;
@property (nonatomic, strong) UILabel *xsAddMaterialLabel;
// 我的声音
@property (nonatomic, strong) UIButton *xsMyVoiceButton;

@property (nonatomic, strong) TextViewWithPlaceholder *xsInputCopywritingTextV;// 输入文案

@property (nonatomic, strong) UIButton *xsInputCopywritingButton;// 覆盖输入文案的button

//@property (nonatomic, strong) UIView *bottomView;

//@property (nonatomic, strong) XSButton *xsPreviewButton;//预览
//@property (nonatomic, strong) XSButton *xsExportButton;//导出

// 智能划词
@property (nonatomic, strong) XSButton *xsZhiNengHuaCiButton;
// 智能划词Label
@property (nonatomic, strong) UILabel *xsZhiNengHuaCiLabel;

@end


@implementation xsDigitalRobotBottomView



- (instancetype)init{
    
    if (self = [super init]) {
        self.backgroundColor = UIColor.clearColor;
        
 
//
            
        [self addSubview:self.xsContentView];
        
        [self.xsContentView addSubview:self.topView];
        
        [self.topView addSubview:self.changeAudioButton];
        [self.changeAudioButton addSubview:self.changeAudioImageV];
        [self.changeAudioButton addSubview:self.changeAudioLabel];
        
//    [self.topView addSubview:self.xsExportButton];//导出
//    [self.topView addSubview:self.xsPreviewButton];//预览
        
        
        [self.topView addSubview:self.xsTitleButton];
        [self.xsTitleButton addSubview:self.xsTitleImageV];
        [self.xsTitleButton addSubview:self.xsTitleLabel];
        
        [self.topView addSubview:self.xsMaterialButton];
        [self.xsMaterialButton addSubview:self.xsMaterialImageV];
        [self.xsMaterialButton addSubview:self.xsMaterialLabel];
        
        [self.topView addSubview:self.xsSubtitlesButton];
        [self.xsSubtitlesButton addSubview:self.xsSubtitlesImageV];
        [self.xsSubtitlesButton addSubview:self.xsSubtitlesLabel];
        
        
        [self.xsContentView addSubview:self.bottomView];
//        self.bottomView.backgroundColor = UIColor.grayColor;
        
//[self.bottomView addSubview:self.xsDigitalRobotScrollView];
//[self.xsDigitalRobotScrollView addSubview:self.xsDigitalRobotSubBgView];
        [self.bottomView addSubview:self.xsVideoTitleLabel];
        
        
        [self.bottomView addSubview:self.xsMyVoiceButton];
        
        [self.bottomView addSubview:self.xsAddMaterialButton];
        [self.xsAddMaterialButton addSubview:self.xsAddMaterialImageV];
        [self.xsAddMaterialButton addSubview:self.xsAddMaterialLabel];
        
        
        [self.bottomView addSubview:self.xsInputCopywritingTextV];
        [self.bottomView addSubview:self.xsInputCopywritingButton];
        
        [self.bottomView addSubview:self.xsZhiNengHuaCiLabel];
        [self.bottomView addSubview:self.xsZhiNengHuaCiButton];
        
      
        
        
    }
    return self;
}



- (UIButton *)xsInputCopywritingButton{
    if (!_xsInputCopywritingButton) {
        _xsInputCopywritingButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _xsInputCopywritingButton.backgroundColor = UIColor.clearColor;
        [_xsInputCopywritingButton addTarget:self action:@selector(xsInputCopywritingButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _xsInputCopywritingButton;
}
- (void)xsInputCopywritingButtonAction:(UIButton *)sender{
    XSLog(@"xsInputCopywritingButtonAction\n\n");
    
    
    if([self.delegate respondsToSelector:@selector(xsInputCopywritingButtonButtonEvent:)]){
        [self.delegate xsInputCopywritingButtonButtonEvent:sender];
    }
}


- (TextViewWithPlaceholder *)xsInputCopywritingTextV{
    
    if(!_xsInputCopywritingTextV){
        _xsInputCopywritingTextV = [[TextViewWithPlaceholder alloc] initWithFrame:CGRectZero];
        _xsInputCopywritingTextV.font = Font(16);
        _xsInputCopywritingTextV.textColor = UIColor.whiteColor;
        _xsInputCopywritingTextV.text = @"输入文案";
//        _xsInputCopywritingTextV.text = @"024年8月28日13时许，王某（女，38岁，崂山区人）驾车行至崂山区青山村观景台附近时逆向行驶，因对向正常行驶的林某某（男，26岁崂山区人）未对其让行，王某下车对林某某进行辱骂、殴打。公安机关接报后迅速开展工作，将王某查获。8月29日，青岛市公安局崂山分局发布情况通报称：2024年8月28日13时许，王某（女，38岁，崂山区人）驾车行至崂山区青山村观景台附近时逆向行驶，因对向正常行驶的林某某（男，26岁崂山区人）未对其让行，王某下车对林某某进行辱骂、殴打。公安机关接报后迅速开展工作，将王某查获。8月29日，青岛市公安局崂山分局发布情况通报称：2024年8月28日13时许，王某（女，38岁，崂山区人）驾车行至崂山区青山村观景台附024年8月28日13时许，王某（女，38岁，崂山区人）驾车行至崂山区青山村观景台附近时逆向行驶，因对向正常行驶的林某某（男，26岁崂山区人）未对其让行，王某下车对林某某进行辱骂、殴打。公安机关接报后迅速开展工作，将王某查获。8月29日，青岛市公安局崂山分局发布情况通报称：2024年8月28日13时许，王某（女，38岁，崂山区人）驾车行至崂山区青山村观景台附近时逆向行驶，因对向正常行驶的林某某（男，26岁崂山区人）未对其让行，王某下车对林某某进行辱骂、殴打。公安机关接报后迅速开展工作，将王某查获。8月29日，青岛市公安局崂山分局发布情况通报称：2024年8月28日13时许，王某（女，38岁，崂山区人）驾车行至崂山区青山村观景台附";
//        _xsInputCopywritingTextV.attributedText = ;
        _xsInputCopywritingTextV.backgroundColor = UIColor.clearColor;
        _xsInputCopywritingTextV.textAlignment = NSTextAlignmentLeft;
        _xsInputCopywritingTextV.delegate = self;
        //_xsInputCopywritingTextV.text = @"发布情况通报称";
        //：2024年8月28日13时许，王某（女，38岁，崂山区人）驾车行至崂山区青山村观景台附近时逆向行驶，因对向正常行驶的林某某（男，26岁崂山区人）未对其让行，王某下车对林某某进行辱骂、殴打。公安机关接报后迅速开展工作，将王某查获。8月29日，青岛市公安局崂山分局发布情况通报称：2024年8月28日13时许，王某（女，38岁，崂山区人）驾车行至崂山区青山村观景台附近时逆向行驶，因对向正常行驶的林某某（男，26岁崂山区人）未对其让行，王某下车对林某某进行辱骂、殴打。公安机关接报后迅速开展工作，将王某查获。8月29日，青岛市公安局崂山分局发布情况通报称：2024年8月28日13时许，王某（女，38岁，崂山区人）驾车行至崂山区青山村观景台附近时逆向行驶，因对向正常行驶的林某某（男，26岁崂山区人）未对其让行，王某下车对林某某进行辱骂、殴打。公安机关接报后迅速开展工作，将王某查获。
        
        //NSMutableAttributedString *recommendTFattributedString = [[NSMutableAttributedString alloc] initWithString:kLocalizedString(@"输入文案")attributes:@{NSFontAttributeName:Font(16),NSForegroundColorAttributeName:COLOR_TextGray88}];
        _xsInputCopywritingTextV.placeholder = @"输入视频文案";
    }
    return _xsInputCopywritingTextV;
}
#pragma mark 设置视频文案文字
- (void)xsChangeInputCopywritingTextVWithString:(NSString *)textStr{
    
    
    if(textStr.length>=0&&textStr.length<=800){
        self.xsInputCopywritingTextV.text = textStr;
    }
    else{
        self.xsInputCopywritingTextV.text = [textStr substringToIndex:800];
    }
    
    self.xsZhiNengHuaCiLabel.text = [NSString stringWithFormat:@"%ld/800",self.xsInputCopywritingTextV.text.length];
    
    if(!kStringIsEmpty(self.xsInputCopywritingTextV.text)){
        self.xsZhiNengHuaCiLabel.hidden = NO;
        self.xsZhiNengHuaCiButton.hidden = NO;
    }
    else{
        self.xsZhiNengHuaCiLabel.hidden = YES;
        self.xsZhiNengHuaCiButton.hidden = YES;
    }
}

#pragma mark 获取频文案文字
- (NSString *)xsGetInputCopywritingText{
    return [self.xsInputCopywritingTextV.text copy];
}

#pragma mark UITextViewDelegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    // 检查替换文本是否为换行符（Return 键产生的）
    // 注意：这里检查的是 "\n"，因为 Return 键在 `UITextView` 中通常产生换行符
    if ([text isEqualToString:@"\n"]) {
        // 在这里执行你想要的操作，比如提交表单
        NSLog(@"Return 键被点击了");
  
        [self.xsInputCopywritingTextV resignFirstResponder];
        
        if([self.delegate respondsToSelector:@selector(DigitalRobotBottomViewCopywritingTextViewTextChange:)]){
            [self.delegate DigitalRobotBottomViewCopywritingTextViewTextChange:self.xsInputCopywritingTextV.text];
        }
        
        // 如果你不希望文本视图插入换行符，可以返回 NO
        // 否则，返回 YES 允许替换发生
        return NO; // 或者 YES，取决于你的需求
    }
    return YES;
}
- (void)textViewDidChangeSelection:(UITextView *)textView{
    
    NSLog(@"textViewDidChangeSelection-textView.text==%@",textView.text);
    
}
- (UIButton *)xsMyVoiceButton{
    
    if(!_xsMyVoiceButton){
        _xsMyVoiceButton = [UIButton buttonWithType:UIButtonTypeCustom];
        
[_xsMyVoiceButton setTitle:kLocalizedString(@"我的声音") forState:UIControlStateNormal];
[_xsMyVoiceButton setTitleColor:COLOR_textWhiteColor forState:UIControlStateNormal];
_xsMyVoiceButton.font = Font(13);
[_xsMyVoiceButton setImage:[UIImage imageNamed:@"xsBossMyVoiceImg"] forState:UIControlStateNormal];
        [_xsMyVoiceButton addTarget:self action:@selector(xsMyVoiceButtonBeclick:) forControlEvents:UIControlEventTouchUpInside];
        _xsMyVoiceButton.layer.cornerRadius = 2.0;
        _xsMyVoiceButton.layer.masksToBounds = YES;
        _xsMyVoiceButton.backgroundColor = COLOR_HEX(0x343543);
    }
    return _xsMyVoiceButton;
}
- (void)xsMyVoiceButtonBeclick:(UIButton *)sender{
    
    
    NSLog(@"xsMyVoiceButtonBeclick");
    
    if([self.delegate respondsToSelector:@selector(DigitalRobotBottomViewMyVoiceButtonEvent:)]){
        [self.delegate DigitalRobotBottomViewMyVoiceButtonEvent:sender];
    }
}

- (UIButton *)xsAddMaterialButton{
    
    if(!_xsAddMaterialButton){
        _xsAddMaterialButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _xsAddMaterialButton.backgroundColor = UIColor.clearColor;
        [_xsAddMaterialButton addTarget:self action:@selector(xsAddMaterialButtonBeclick:) forControlEvents:UIControlEventTouchUpInside];
        _xsAddMaterialButton.layer.cornerRadius = 2.0;
        _xsAddMaterialButton.layer.masksToBounds = YES;
        _xsAddMaterialButton.backgroundColor = COLOR_HEX(0x343543);
    }
    return _xsAddMaterialButton;
}
- (void)xsAddMaterialButtonBeclick:(UIButton *)sender{
    
    
    NSLog(@"xsAddMaterialButtonBeclick");
    if([self.delegate respondsToSelector:@selector(DigitalRobotBottomViewAddMaterialButtonEvent:)]){
        [self.delegate DigitalRobotBottomViewAddMaterialButtonEvent:sender];
    }
}

- (UIImageView *)xsAddMaterialImageV{
    if(!_xsAddMaterialImageV){
        _xsAddMaterialImageV = [[UIImageView alloc] init];
        _xsAddMaterialImageV.backgroundColor = UIColor.clearColor;
        _xsAddMaterialImageV.image = [UIImage imageNamed:@"bossIPEdit_icon_add"];
    }
    return _xsAddMaterialImageV;
}
- (UILabel *)xsAddMaterialLabel{
    if (!_xsAddMaterialLabel) {
        _xsAddMaterialLabel = [[UILabel alloc] init];
        _xsAddMaterialLabel.backgroundColor = UIColor.clearColor;
        _xsAddMaterialLabel.font = Font(13);
        _xsAddMaterialLabel.textColor = UIColor.whiteColor;
        _xsAddMaterialLabel.numberOfLines = 1;
        _xsAddMaterialLabel.text = @"添加素材";
        _xsAddMaterialLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _xsAddMaterialLabel;
}

// 改变显示添加素材文本左边小图标
- (void)xsChangeAddMaterialLabelLeftIcon:(NSString *)leftIconImageUrl{
    
   
    if([leftIconImageUrl hasPrefix:@"http"]){
        [self.xsAddMaterialImageV sd_setImageWithURL:[NSURL URLWithString:leftIconImageUrl] placeholderImage:[UIImage imageNamed:@"bossIPEdit_icon_add"]];
    }
    else{
        self.xsAddMaterialImageV.image = [UIImage imageNamed:leftIconImageUrl];
    }
    
}


- (UIButton *)xsSubtitlesButton{
    
    if(!_xsSubtitlesButton){
        _xsSubtitlesButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _xsSubtitlesButton.backgroundColor = UIColor.clearColor;
        [_xsSubtitlesButton addTarget:self action:@selector(xsSubtitlesButtonBeclick:) forControlEvents:UIControlEventTouchUpInside];
        _xsSubtitlesButton.selected = NO;
    }
    return _xsSubtitlesButton;
}

#pragma mark 字幕按钮被点击
- (void)xsSubtitlesButtonBeclick:(UIButton *)sender{
    
    
    NSLog(@"xsSubtitlesButtonBeclick");
    sender.selected = !sender.selected;
    
    if(sender.selected){
        _xsSubtitlesImageV.image = [UIImage imageNamed:@"bossIPBoxSelect"];
    }
    else{
        _xsSubtitlesImageV.image = [UIImage imageNamed:@"bossIPBoxNormal"];
    }
    
    if(self.xsSubtitlesCallbackBlock){
        self.xsSubtitlesCallbackBlock(sender);
    }
}
// 字幕按钮是否被点击
// isClickStatu YES被点击了  NO未被点击
- (void)xsChangeSubtitlesButtonIsClick:(BOOL)isClickStatu{
    
    self.xsSubtitlesButton.selected = isClickStatu;
    if(self.xsSubtitlesButton.selected){
        _xsSubtitlesImageV.image = [UIImage imageNamed:@"bossIPBoxSelect"];
    }
    else{
        _xsSubtitlesImageV.image = [UIImage imageNamed:@"bossIPBoxNormal"];
    }
    
}
- (UIImageView *)xsSubtitlesImageV{
    if(!_xsSubtitlesImageV){
        _xsSubtitlesImageV = [[UIImageView alloc] init];
        _xsSubtitlesImageV.backgroundColor = UIColor.clearColor;
        _xsSubtitlesImageV.image = [UIImage imageNamed:@"bossIPBoxNormal"];
    }
    return _xsSubtitlesImageV;
}
- (UILabel *)xsSubtitlesLabel{
    if (!_xsSubtitlesLabel) {
        _xsSubtitlesLabel = [[UILabel alloc] init];
        _xsSubtitlesLabel.backgroundColor = UIColor.clearColor;
        _xsSubtitlesLabel.font = [UIFont systemFontOfSize:16];
        _xsSubtitlesLabel.textColor = UIColor.whiteColor;
        _xsSubtitlesLabel.numberOfLines = 1;
        _xsSubtitlesLabel.text = @"字幕";
        _xsSubtitlesLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _xsSubtitlesLabel;
}


- (UIButton *)xsTitleButton{
    
    if(!_xsTitleButton){
        _xsTitleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _xsTitleButton.backgroundColor = UIColor.clearColor;
        _xsTitleButton.selected = NO;
        [_xsTitleButton addTarget:self action:@selector(xsTitleButtonBeclick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _xsTitleButton;
}

#pragma mark 标题按钮被点击
- (void)xsTitleButtonBeclick:(UIButton *)sender{
    
    
    NSLog(@"xsTitleButtonBeclick");
    sender.selected = !sender.selected;
    if(sender.selected){
        _xsTitleImageV.image = [UIImage imageNamed:@"bossIPBoxSelect"];
    }
    else{
        _xsTitleImageV.image = [UIImage imageNamed:@"bossIPBoxNormal"];
    }
    if(self.xsTitleCallbackBlock){
        self.xsTitleCallbackBlock(sender);
    }
}
// 标题按钮按钮是否被点击
// isClickStatu YES被点击了  NO未被点击
- (void)xsChangeTitleButtonIsClick:(BOOL)isClickStatu{
    
    self.xsTitleButton.selected = isClickStatu;
    if(self.xsTitleButton.selected){
        _xsTitleImageV.image = [UIImage imageNamed:@"bossIPBoxSelect"];
    }
    else{
        _xsTitleImageV.image = [UIImage imageNamed:@"bossIPBoxNormal"];
    }
}

- (UIImageView *)xsTitleImageV{
    if(!_xsTitleImageV){
        _xsTitleImageV = [[UIImageView alloc] init];
        _xsTitleImageV.backgroundColor = UIColor.clearColor;
        _xsTitleImageV.image = [UIImage imageNamed:@"bossIPBoxNormal"];
    }
    return _xsTitleImageV;
}
- (UILabel *)xsTitleLabel{
    if (!_xsTitleLabel) {
        _xsTitleLabel = [[UILabel alloc] init];
        _xsTitleLabel.backgroundColor = UIColor.clearColor;
        _xsTitleLabel.font = [UIFont systemFontOfSize:16];
        _xsTitleLabel.textColor = UIColor.whiteColor;
        _xsTitleLabel.numberOfLines = 1;
        _xsTitleLabel.text = @"标题";
        _xsTitleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _xsTitleLabel;
}






- (UIButton *)xsMaterialButton{
    
    if(!_xsMaterialButton){
        _xsMaterialButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _xsMaterialButton.backgroundColor = UIColor.clearColor;
        _xsMaterialButton.selected = NO;
        [_xsMaterialButton addTarget:self action:@selector(xsMaterialButtonBeclick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _xsMaterialButton;
}

#pragma mark 素材按钮被点击
- (void)xsMaterialButtonBeclick:(UIButton *)sender{
    
    
    NSLog(@"xsMaterialButtonBeclick");
    sender.selected = !sender.selected;
    if(sender.selected){
        _xsMaterialImageV.image = [UIImage imageNamed:@"bossIPBoxSelect"];
    }
    else{
        _xsMaterialImageV.image = [UIImage imageNamed:@"bossIPBoxNormal"];
    }
    
    if(self.xsMaterialCallbackBlock){
        self.xsMaterialCallbackBlock(sender);
    }
}
// isClickStatu YES被点击了  NO未被点击
- (void)xsChangeMaterialButtonIsClick:(BOOL)isClickStatu{
    
    self.xsMaterialButton.selected = isClickStatu;
    if(self.xsMaterialButton.selected){
        self.xsMaterialImageV.image = [UIImage imageNamed:@"bossIPBoxSelect"];
    }
    else{
        self.xsMaterialImageV.image = [UIImage imageNamed:@"bossIPBoxNormal"];
    }
}
- (UIImageView *)xsMaterialImageV{
    if(!_xsMaterialImageV){
        _xsMaterialImageV = [[UIImageView alloc] init];
        _xsMaterialImageV.backgroundColor = UIColor.clearColor;
        _xsMaterialImageV.image = [UIImage imageNamed:@"bossIPBoxNormal"];
    }
    return _xsMaterialImageV;
}
- (UILabel *)xsMaterialLabel{
    if (!_xsMaterialLabel) {
        _xsMaterialLabel = [[UILabel alloc] init];
        _xsMaterialLabel.backgroundColor = UIColor.clearColor;
        _xsMaterialLabel.font = [UIFont systemFontOfSize:16];
        _xsMaterialLabel.textColor = UIColor.whiteColor;
        _xsMaterialLabel.numberOfLines = 1;
        _xsMaterialLabel.text = @"素材";
        _xsMaterialLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _xsMaterialLabel;
}


- (UIButton *)changeAudioButton{
    
    if(!_changeAudioButton){
        _changeAudioButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _changeAudioButton.backgroundColor = UIColor.blackColor;
        [_changeAudioButton addTarget:self action:@selector(changeAudioButtonBeclick:) forControlEvents:UIControlEventTouchUpInside];
        _changeAudioButton.titleLabel.font = Font(16);
        [_changeAudioButton setTitleColor:COLOR_textWhiteColor forState:UIControlStateNormal];
        [_changeAudioButton setTitle:@"00:00" forState:UIControlStateNormal];
    }
    return _changeAudioButton;
}
- (void)changeAudioButtonBeclick:(UIButton *)sender{
    
    NSLog(@"changeAudioButtonBeclick");
}



- (UIImageView *)changeAudioImageV{
    if(!_changeAudioImageV){
        _changeAudioImageV = [[UIImageView alloc] init];
        _changeAudioImageV.backgroundColor = UIColor.clearColor;
        _changeAudioImageV.image = [UIImage imageNamed:@"bossIPDefaultImage"];
    }
    return _changeAudioImageV;
}
- (UILabel *)changeAudioLabel{
    if (!_changeAudioLabel) {
        _changeAudioLabel = [[UILabel alloc] init];
        _changeAudioLabel.backgroundColor = UIColor.clearColor;
        _changeAudioLabel.font = [UIFont systemFontOfSize:16];
        _changeAudioLabel.textColor = UIColor.whiteColor;
        _changeAudioLabel.numberOfLines = 1;
        _changeAudioLabel.text = @"亲切姐姐";
        _changeAudioLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _changeAudioLabel;
}



- (UIView *)topView{
    if(!_topView){
        _topView = [[UIView alloc] init];
        _topView.backgroundColor = UIColor.clearColor;
    }
    return _topView;
}
- (UIView *)bottomView{
    if(!_bottomView){
        _bottomView = [[UIView alloc] init];
        _bottomView.backgroundColor = COLOR_HEX(0x212333);//UIColor.clearColor;
    }
    return _bottomView;
}


- (UIView *)xsContentView{
    if(!_xsContentView){
        _xsContentView = [[UIView alloc] init];
        _xsContentView.backgroundColor = UIColor.clearColor;
    }
    return _xsContentView;
}
- (UILabel *)xsVideoTitleLabel{
    
    if (!_xsVideoTitleLabel) {
        _xsVideoTitleLabel = [[UILabel alloc] init];
        _xsVideoTitleLabel.backgroundColor = UIColor.clearColor;
        _xsVideoTitleLabel.font = FontMedium(18);// FontSemibold(17);
        _xsVideoTitleLabel.textColor = UIColor.whiteColor;//COLOR_TextGray9B;
        _xsVideoTitleLabel.numberOfLines = 1;
        _xsVideoTitleLabel.text = kLocalizedString(@"视频文案");
        _xsVideoTitleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _xsVideoTitleLabel;
    
}
//- (UIScrollView *)xsDigitalRobotScrollView
//{
//    if(!_xsDigitalRobotScrollView){
//        _xsDigitalRobotScrollView = [[UIScrollView alloc] init];
//        _xsDigitalRobotScrollView.backgroundColor = COLOR_HEX(0x303030);//UIColor.purpleColor;
//        
////        _xsDigitalRobotScrollView.delegate = self;
////        _xsDigitalRobotScrollView.pagingEnabled = YES;
//        _xsDigitalRobotScrollView.showsHorizontalScrollIndicator = NO;
//        _xsDigitalRobotScrollView.showsVerticalScrollIndicator = NO;
//    }
//    return _xsDigitalRobotScrollView;
//}

//
//- (void)buttonClicked:(UIButton *)sender {
//    NSInteger selectedIndex = sender.tag;
//    NSLog(@"Selected index: %ld", (long)selectedIndex);
//    
//    // 在这里切换底部视图
//    // ...
//}
-(void)layoutSubviews{
    [super layoutSubviews];
    //_recorder.preViewLayer.frame = self.frame;
    
    NSLog(@"layoutSubviews--self.bounds==%@",NSStringFromCGRect(self.bounds));
    
    
    
}




- (void)updateConstraints{
    [super updateConstraints];
    
    //__weak __typeof (&*self)weakSelf = self;
    
    NSLog(@"updateConstraints");
    
    
}

- (void)xsChangeFrame{
    
    [self addSubview:self.xsContentView];
    [self.xsContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    CGFloat margin15 = 15.0;
    CGFloat margin5 = 5.0;
    CGFloat margin20 = 20.0;
    CGFloat margin10 = 10.0;
    
    CGFloat btnIconSize12 = 18.0;
    
    CGFloat screenW = self.bounds.size.width;
    CGFloat screenH = self.bounds.size.height;
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left).offset(margin10);
        make.right.equalTo(self.mas_right).offset(-margin10);
        make.height.mas_equalTo(50);
    }];
    

    [self.topView addSubview:self.changeAudioButton];
    [self.changeAudioButton addSubview:self.changeAudioImageV];
    [self.changeAudioButton addSubview:self.changeAudioLabel];
    
    
    
    // 字幕
    [self.xsSubtitlesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.topView.mas_right).offset(-margin10);
        make.centerY.equalTo(self.topView.mas_centerY);
    }];
    [self.xsSubtitlesImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.xsSubtitlesLabel.mas_left).offset(-margin5);
        make.centerY.equalTo(self.topView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(btnIconSize12, btnIconSize12));
    }];
    [self.xsSubtitlesButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.xsSubtitlesImageV.mas_left);//.offset(10);
        make.centerY.equalTo(self.topView.mas_centerY);
        make.height.mas_equalTo(40);
        make.right.equalTo(self.xsSubtitlesLabel.mas_right);
    }];
    
    
    // 标题
    [self.xsTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.xsSubtitlesButton.mas_left).offset(-margin15);
        make.centerY.equalTo(self.topView.mas_centerY);
    }];
    [self.xsTitleImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.xsTitleLabel.mas_left).offset(-margin5);
        make.centerY.equalTo(self.topView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(btnIconSize12, btnIconSize12));
    }];
    [self.xsTitleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.xsTitleImageV.mas_left);//.offset(10);
        make.centerY.equalTo(self.topView.mas_centerY);
        make.height.mas_equalTo(40);
        make.right.equalTo(self.xsTitleLabel.mas_right);
    }];
    

    
    // 素材
    [self.xsMaterialLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.xsTitleButton.mas_left).offset(-margin15);
            make.centerY.equalTo(self.topView.mas_centerY);
//        make.right.equalTo(self.xsTitleButton.mas_left).offset(-margin15);
//        make.centerY.equalTo(self.topView.mas_centerY);
    }];
    [self.xsMaterialImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.xsMaterialLabel.mas_left).offset(-margin5);
        make.centerY.equalTo(self.topView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(btnIconSize12, btnIconSize12));
    }];
    [self.xsMaterialButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.xsMaterialImageV.mas_left);//.offset(10);
        make.centerY.equalTo(self.topView.mas_centerY);
        make.height.mas_equalTo(40);
        make.right.equalTo(self.xsMaterialLabel.mas_right);
    }];
    
    
    
    
   

    
  
    
    
    

    
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.topView.mas_left);//.offset(10);
        make.right.equalTo(self.topView.mas_right);//.offset(10);
        make.top.equalTo(self.topView.mas_bottom).offset(margin10);
        make.bottom.equalTo(self.xsContentView.mas_bottom).offset(-margin10);
    }];
    self.bottomView.layer.cornerRadius = 8.0;
    self.bottomView.layer.masksToBounds = YES;
 

    
    [self.xsVideoTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bottomView.mas_left).offset(margin15);
        make.top.equalTo(self.bottomView.mas_top).offset(5);
        make.height.mas_equalTo(xsDigitalRobotScrollViewHeight-14);
        make.width.mas_equalTo(screenW-margin20*2.0);
    }];
    

    
    // 我的声音
    [self.xsMyVoiceButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.bottomView.mas_bottom).offset(-margin15);
        make.left.equalTo(self.bottomView.mas_left).offset(margin15);
        //make.size.mas_equalTo(CGSizeMake(75.0, 40));
        make.height.mas_equalTo(25);
    }];
    
    // 添加素材
    [self.xsAddMaterialImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.bottomView.mas_bottom).offset(-margin15);
        make.left.equalTo(self.xsMyVoiceButton.mas_right).offset(margin15);
        make.size.mas_equalTo(CGSizeMake(btnIconSize12, btnIconSize12));
    }];
    [self.xsAddMaterialLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.xsAddMaterialImageV.mas_right).offset(margin5);
        make.centerY.equalTo(self.xsAddMaterialImageV.mas_centerY);
    }];
    [self.xsAddMaterialButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.xsAddMaterialImageV.mas_left);//.offset(10);
        make.centerY.equalTo(self.xsAddMaterialImageV.mas_centerY);
        make.height.mas_equalTo(25);
        make.right.equalTo(self.xsAddMaterialLabel.mas_right);
    }];
  

    
    [self.xsZhiNengHuaCiButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.bottomView.mas_bottom).offset(-margin10);
        make.right.equalTo(self.bottomView.mas_right).offset(-margin5);
        make.height.mas_equalTo(20);
    }];
    
    [self.xsZhiNengHuaCiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.xsZhiNengHuaCiButton.mas_top).offset(-2);
        make.right.equalTo(self.xsZhiNengHuaCiButton.mas_right);//.offset(-margin5);
        make.height.mas_equalTo(20);
    }];
    
    
    [self.xsInputCopywritingTextV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.xsVideoTitleLabel.mas_bottom);//.offset(margin10);
        make.bottom.equalTo(self.xsZhiNengHuaCiLabel.mas_top);//.offset(-margin10);
        make.left.equalTo(self.bottomView.mas_left).offset(margin10);
        make.right.equalTo(self.topView.mas_right).offset(-margin10);
    }];
    
    
    [self.xsInputCopywritingButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.xsInputCopywritingTextV);
    }];
    
    self.xsZhiNengHuaCiLabel.hidden = YES;
    self.xsZhiNengHuaCiButton.hidden = YES;
    
    
    self.xsMyVoiceButton.hidden = YES;
    self.xsAddMaterialImageV.hidden = YES;
    self.xsAddMaterialLabel.hidden = YES;
    self.xsAddMaterialButton.hidden = YES;
    
    
    // 是否设置过素材文本
    self.isHadMaterialLabel = NO;
    // 是否设置过music文本
    self.isHadMyVoiceButtonTitle = NO;
    
//    [self addDigitalRobotView];
}


- (void)digitalRobotButtonClicked:(UIButton *)sender{
    
    
    NSLog(@"digitalRobotButtonClicked--sender.tag==%ld",sender.tag);
}


- (UILabel *)xsZhiNengHuaCiLabel{
    
    if (!_xsZhiNengHuaCiLabel) {
        _xsZhiNengHuaCiLabel = [[UILabel alloc] init];
        _xsZhiNengHuaCiLabel.backgroundColor = UIColor.clearColor;
        _xsZhiNengHuaCiLabel.font = Font(14);// FontSemibold(17);
        _xsZhiNengHuaCiLabel.textColor = COLOR_textWhiteColor;
        _xsZhiNengHuaCiLabel.numberOfLines = 1;
        _xsZhiNengHuaCiLabel.text = @"0/800";//kLocalizedString(@"智能划词");
        _xsZhiNengHuaCiLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _xsZhiNengHuaCiLabel;
    
}
- (XSButton *)xsZhiNengHuaCiButton{// 智能划词
    if (!_xsZhiNengHuaCiButton) {
        _xsZhiNengHuaCiButton = [XSButton buttonWithType:UIButtonTypeCustom];
        _xsZhiNengHuaCiButton.backgroundColor = UIColor.clearColor;
        _xsZhiNengHuaCiButton.titleLabel.font = Font(14);
        [_xsZhiNengHuaCiButton setTitleColor:COLOR_textWhiteColor forState:UIControlStateNormal];
        [_xsZhiNengHuaCiButton setTitle:kLocalizedString(@"智能划词") forState:UIControlStateNormal];
        [_xsZhiNengHuaCiButton setImage:[UIImage imageNamed:@"bossIPBoxNormal_hc"] forState:UIControlStateNormal];
        [_xsZhiNengHuaCiButton setImage:[UIImage imageNamed:@"bossIPBoxSelect_hc"] forState:UIControlStateSelected];
        [_xsZhiNengHuaCiButton addTarget:self action:@selector(xsZhiNengHuaCiButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        _xsZhiNengHuaCiButton.selected = NO;
        
        
    }
    return _xsZhiNengHuaCiButton;
}
- (void)xsZhiNengHuaCiButtonAction:(UIButton *)btn{
    XSLog(@"xsZhiNengHuaCiButtonAction\n\n");
    
    btn.selected = !btn.selected;
    
    
    if([self.delegate respondsToSelector:@selector(xsZhiNengHuaCiButtonEvent:)]){
        [self.delegate xsZhiNengHuaCiButtonEvent:btn];
    }
}

//isShowStatu  YES显示  NO隐藏
- (void)xsIsShowZhiNengHuaCiButton:(BOOL)isShowStatu{
    
    self.xsZhiNengHuaCiButton.hidden = !isShowStatu;
}

//isShowStatu  YES显示  NO隐藏
- (void)xsIsShowZhiNengHuaCiLabel:(BOOL)isShowStatu{
    
    self.xsZhiNengHuaCiLabel.hidden = !isShowStatu;
}

#pragma mark 改变 我的声音  添加素材位置
// 改变 我的声音  添加素材位置
- (void)xsChangeMyVoicAddMaterialLocationFrame{
    
    CGFloat margin15 = 15.0;
    CGFloat margin5 = 5.0;
    CGFloat btnIconSize12 = 12.0;
    
//    // 我的声音
//    [self.xsMyVoiceButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.equalTo(self.bottomView.mas_bottom);//.offset(-margin15);
//        make.left.equalTo(self.bottomView.mas_left).offset(margin15);
//        make.size.mas_equalTo(CGSizeMake(75.0, 40));
//    }];
//    
//    // 添加素材
//    [self.xsAddMaterialImageV mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.equalTo(self.bottomView.mas_bottom).offset(-margin15);
//        make.left.equalTo(self.xsMyVoiceButton.mas_right).offset(margin15);
//        make.size.mas_equalTo(CGSizeMake(btnIconSize12, btnIconSize12));
//    }];
//    [self.xsAddMaterialLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.xsAddMaterialImageV.mas_right).offset(margin5);
//        make.centerY.equalTo(self.xsAddMaterialImageV.mas_centerY);
//    }];
//    [self.xsAddMaterialButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.xsAddMaterialImageV.mas_left);//.offset(10);
//        make.centerY.equalTo(self.xsAddMaterialImageV.mas_centerY);
//        make.height.mas_equalTo(40);
//        make.right.equalTo(self.xsAddMaterialLabel.mas_right);
//    }];
  
}

#pragma mark 改变显示的音乐标题
- (void)xsChangeMyVoiceButtonTitle:(NSString *)changeString{
    
    [self.xsMyVoiceButton setTitle:[NSString stringWithFormat:@"  %@  ",changeString] forState:UIControlStateNormal];
    
    [self.xsMyVoiceButton setImageEdgeInsets:UIEdgeInsetsMake(0, 3, 0, 0)];
    
    // 是否设置过music文本
    self.isHadMyVoiceButtonTitle = YES;
    
    CGFloat margin15 = 15.0;
    CGFloat btnIconSize12 = 12.0;
    CGFloat margin5 = 5.0;
    
    self.xsMyVoiceButton.hidden = NO;
    
    
    
    // 是否设置过素材文本
    if(self.isHadMaterialLabel==YES){
        
        // 我的声音
        [self.xsMyVoiceButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.bottomView.mas_bottom).offset(-margin15);
            make.left.equalTo(self.bottomView.mas_left).offset(margin15);
            //make.size.mas_equalTo(CGSizeMake(75.0, 40));
            make.height.mas_equalTo(25);
        }];
        
        // 添加素材
        [self.xsAddMaterialImageV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.xsMyVoiceButton.mas_centerY);
            make.left.equalTo(self.xsMyVoiceButton.mas_right).offset(margin15);
            make.size.mas_equalTo(CGSizeMake(btnIconSize12, btnIconSize12));
        }];
        [self.xsAddMaterialLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.xsAddMaterialImageV.mas_right).offset(margin5);
            make.centerY.equalTo(self.xsAddMaterialImageV.mas_centerY);
        }];
        [self.xsAddMaterialButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.xsAddMaterialImageV.mas_left).offset(-5);
            make.centerY.equalTo(self.xsAddMaterialImageV.mas_centerY);
            make.height.mas_equalTo(25);
            make.right.equalTo(self.xsAddMaterialLabel.mas_right).offset(5);
        }];
        
        self.xsAddMaterialImageV.hidden = NO;
        self.xsAddMaterialLabel.hidden = NO;
        self.xsAddMaterialButton.hidden = NO;
    }
    else{
        self.xsAddMaterialImageV.hidden = YES;
        self.xsAddMaterialLabel.hidden = YES;
        self.xsAddMaterialButton.hidden = YES;
        // 我的声音
        [self.xsMyVoiceButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.bottomView.mas_bottom).offset(-margin15);
            make.left.equalTo(self.bottomView.mas_left).offset(margin15);
            //make.size.mas_equalTo(CGSizeMake(75.0, 40));
            make.height.mas_equalTo(25);
        }];
    }
    
}


#pragma mark 改变显示添加素材文本
- (void)xsChangeAddMaterialLabelText:(NSString *)materialText{
    
    self.xsAddMaterialLabel.text = materialText;//[NSString stringWithFormat:@" %@ ",materialText];
    
    
    
    
    // 是否设置过素材文本
    self.isHadMaterialLabel = YES;
    
    CGFloat margin15 = 15.0;
    CGFloat btnIconSize12 = 12.0;
    CGFloat margin5 = 5.0;
    
    self.xsAddMaterialImageV.hidden = NO;
    self.xsAddMaterialLabel.hidden = NO;
    self.xsAddMaterialButton.hidden = NO;
    
    // 是否设置过music文本
    if(self.isHadMyVoiceButtonTitle==YES){
        
        // 我的声音
        [self.xsMyVoiceButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.bottomView.mas_bottom).offset(-margin15);
            make.left.equalTo(self.bottomView.mas_left).offset(margin15);
            //make.size.mas_equalTo(CGSizeMake(75.0, 40));
            make.height.mas_equalTo(25);
        }];
        
        // 添加素材
        [self.xsAddMaterialImageV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.xsMyVoiceButton.mas_centerY);//.offset(-margin15);
            make.left.equalTo(self.xsMyVoiceButton.mas_right).offset(margin15);
            make.size.mas_equalTo(CGSizeMake(btnIconSize12, btnIconSize12));
        }];
        [self.xsAddMaterialLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.xsAddMaterialImageV.mas_right).offset(margin5);
            make.centerY.equalTo(self.xsAddMaterialImageV.mas_centerY);
        }];
        [self.xsAddMaterialButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.xsAddMaterialImageV.mas_left).offset(-5);
            make.centerY.equalTo(self.xsAddMaterialImageV.mas_centerY);
            make.height.mas_equalTo(25);
            make.right.equalTo(self.xsAddMaterialLabel.mas_right).offset(5);
        }];
        
        self.xsMyVoiceButton.hidden = NO;
    }
    else{
        
        CGFloat xsAddMaterialImageVOffsetY = (margin15-btnIconSize12)*0.5+margin15;
        // 添加素材
        [self.xsAddMaterialImageV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.bottomView.mas_bottom).offset(-xsAddMaterialImageVOffsetY);
            //make.left.equalTo(self.xsMyVoiceButton.mas_right).offset(margin15);
            make.left.equalTo(self.bottomView.mas_left).offset(margin15);
            make.size.mas_equalTo(CGSizeMake(btnIconSize12, btnIconSize12));
        }];
        [self.xsAddMaterialLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.xsAddMaterialImageV.mas_right).offset(margin5);
            make.centerY.equalTo(self.xsAddMaterialImageV.mas_centerY);
        }];
        [self.xsAddMaterialButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.xsAddMaterialImageV.mas_left).offset(-5);
            make.centerY.equalTo(self.xsAddMaterialImageV.mas_centerY);
            make.height.mas_equalTo(25);
            make.right.equalTo(self.xsAddMaterialLabel.mas_right).offset(5);
        }];
        
        self.xsMyVoiceButton.hidden = YES;
    }
    
}

- (void)xsChangeTopViewIsHidden:(BOOL)state{
    self.topView.hidden = state;
}

// 修改添加素材是否隐藏
- (void)xsChangexsAddMaterialButtonHidel:(BOOL)isHden{
    
    self.xsAddMaterialImageV.hidden = isHden;
    self.xsAddMaterialLabel.hidden = isHden;
    self.xsAddMaterialButton.hidden = isHden;
}

@end



